package com.zjf.fupload.entity;

/**
 * 服务器信息
 * @author zjf
 */
public class ServerInfo {

	/**
	 * 名称
	 */
	private String name;
	/**
	 * 服务器地址：ip 或者 域名
	 */
	private String server;
	/**
	 * 端口，默认为21
	 */
	private int port;
	/**
	 * 用户名
	 */
	private String username;
	/**
	 * 密码
	 */
	private String password;
	/**
	 * 上传到路径
	 */
	private String path;
	
	/**
	 * 将一个字符串解析为{@link ServerInfo}，字符串格式必须为：
	 * name:server:port:username:password:path
	 * @param server
	 * 		形式为name:server:port:username:password:path的字符串。
	 * @return
	 * 		{@link ServerInfo}
	 */
	public static ServerInfo parse(String server) {
		String[] infos = server.split(":");
		if(infos.length != 6) {
			return null;
		}
		ServerInfo info = new ServerInfo();
		info.setName(infos[0]);
		info.setServer(infos[1]);
		info.setPort(Integer.parseInt(infos[2]));
		info.setUsername(infos[3]);
		info.setPassword(infos[4]);
		info.setPath(infos[5]);
		return info;
	}
	
	

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}



	public String getServer() {
		return server;
	}

	public void setServer(String server) {
		this.server = server;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ServerInfo other = (ServerInfo) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}



	@Override
	public String toString() {
		return "ServerInfo [name=" + name + ", password=" + password
				+ ", path=" + path + ", port=" + port + ", server=" + server
				+ ", username=" + username + "]";
	}

}
